Click here to Skip to main content
15,868,016 members
Home / Discussions / JavaScript
   

JavaScript

 
AnswerRe: I am creating a program with Visual Basic Script files with C++. Pin
ZurdoDev29-Jun-20 4:35
professionalZurdoDev29-Jun-20 4:35 
Questionhow to get audio play auto work in mobile browsers andriod & ios Pin
Member 1486961821-Jun-20 20:38
Member 1486961821-Jun-20 20:38 
QuestionNeed javascript code support for below request Pin
mikt201618-Jun-20 0:57
mikt201618-Jun-20 0:57 
AnswerRe: Need javascript code support for below request Pin
ZurdoDev18-Jun-20 2:00
professionalZurdoDev18-Jun-20 2:00 
AnswerRe: Need javascript code support for below request Pin
Richard MacCutchan18-Jun-20 4:43
mveRichard MacCutchan18-Jun-20 4:43 
QuestionAccordion not working properly with dynamic content Pin
mhutch2617-Jun-20 4:09
mhutch2617-Jun-20 4:09 
QuestionData from one page to another with a twist. Pin
and180y14-Jun-20 10:33
and180y14-Jun-20 10:33 
AnswerRe: Data from one page to another with a twist. Pin
Richard Deeming15-Jun-20 0:41
mveRichard Deeming15-Jun-20 0:41 
So long as you don't need to support Internet Explorer, the modern way to parse the querystring is to use the URLSearchParams class:
URLSearchParams - Web APIs | MDN[^]
JavaScript
const searchParams = new URLSearchParams(location.search);
for (const [key, value] of searchParams) {
    console.log(key, "=", value);
}
It's not clear what the connection is between the querystring parameters and the form parameters, but the code you've shown requires that they're in exactly the same order. It would probably be better if you could match based on the name of the element.

You'll also need to use the value property, not the textContent property, to set the value for a form element.
JavaScript
const searchParams = new URLSearchParams(location.search);
for (const [key, value] of searchParams) {
    let element = document.getElementsByName(key)[0];
    if (element && element.classList.contains("dropdown") && (/^INPUT|SELECT$/i).test(element.tagName)) {
        element.value = value;
    }
    else {
        console.warn("Unknown element:", key, element);
    }
}




"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer

GeneralRe: Data from one page to another with a twist. Pin
and180y15-Jun-20 1:00
and180y15-Jun-20 1:00 
GeneralRe: Data from one page to another with a twist. Pin
Richard Deeming15-Jun-20 1:15
mveRichard Deeming15-Jun-20 1:15 
GeneralRe: Data from one page to another with a twist. Pin
and180y15-Jun-20 1:24
and180y15-Jun-20 1:24 
GeneralRe: Data from one page to another with a twist. Pin
Richard Deeming15-Jun-20 1:27
mveRichard Deeming15-Jun-20 1:27 
GeneralRe: Data from one page to another with a twist. Pin
and180y15-Jun-20 1:46
and180y15-Jun-20 1:46 
GeneralRe: Data from one page to another with a twist. Pin
Richard Deeming15-Jun-20 4:59
mveRichard Deeming15-Jun-20 4:59 
GeneralRe: Data from one page to another with a twist. Pin
and180y15-Jun-20 8:56
and180y15-Jun-20 8:56 
GeneralRe: Data from one page to another with a twist. Pin
Richard Deeming15-Jun-20 8:58
mveRichard Deeming15-Jun-20 8:58 
GeneralRe: Data from one page to another with a twist. Pin
and180y15-Jun-20 9:07
and180y15-Jun-20 9:07 
GeneralRe: Data from one page to another with a twist. Pin
Richard Deeming15-Jun-20 9:16
mveRichard Deeming15-Jun-20 9:16 
QuestionJavascript function error. Pin
and180y9-Jun-20 13:55
and180y9-Jun-20 13:55 
AnswerRe: Javascript function error. Pin
Richard MacCutchan9-Jun-20 21:03
mveRichard MacCutchan9-Jun-20 21:03 
GeneralRe: Javascript function error. Pin
and180y9-Jun-20 23:27
and180y9-Jun-20 23:27 
GeneralRe: Javascript function error. Pin
Richard MacCutchan9-Jun-20 23:36
mveRichard MacCutchan9-Jun-20 23:36 
GeneralRe: Javascript function error. Pin
and180y10-Jun-20 0:21
and180y10-Jun-20 0:21 
GeneralRe: Javascript function error. Pin
Estys10-Jun-20 0:31
Estys10-Jun-20 0:31 
GeneralRe: Javascript function error. Pin
and180y10-Jun-20 0:59
and180y10-Jun-20 0:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.