Jump to content
  • 0

Use a parameter from a datapage that was passed in by URL, in a javascript function on that page


Billp

Question

I posted this in another forum but the answer I  got just pointed me to a caspio document that I had said in the question I had already poored through.  I have been trying things to get the right syntax but I am really hoping to find someone who can help me avoid all this trial and error.  

I have a parameter passed from Weebly to a datapage using the URL ? syntax.  When used in the datapage the syntax is [@settype] then I use comparisons to hide or show parts of the datapage.  This way only have to have one datapage for both types of information.  But...I want to change the label for entering the email address based on the value of settype and I can't find settype using dynamic labels but it would be very easy in javascript to do this.  But...I have not been able to figure out how to reference settype in the javascript.  Simply using the name of the parameter, as shown below,  doesn't work and I've looked through the doc's on referencing the elements,  hence I can lookup the label and change the innerhtml just fine but I need to do it conditionally.  So, how to reference settype in javascript like this example: (the one that doesn't work):

if (settype == "form1"){

      do the code to change the label

}else{

    do the code to change the label to something else

}

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

  • 0

Hi @Billp, you will need to declare a variable first to get the parameter from the URL. Something like this:

// Get URL search parameters
const urlSearchParams = new URLSearchParams(window.location.search);
// Get value of the 'settype' parameter
const settype = urlSearchParams.get('settype');

// Conditionally change label
const emailLabel = document.querySelector('#email-label');
if (settype === 'form1') {
 // do something
} else {
  // do something
}

 

-Potato

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...