Jump to content

php javascript and sending variables


optikalefx

Recommended Posts

 

Ive been trying for a while and nothing is working

 

so i have this html <select> statement

I have a submit button as well.

 

As it is now, you select from the list, and hit the submit button, which sends the info that was selected as well as a hidden variable.

 

Now what I really need, is to execute that submit button with an onchange of the select statement.

But that would mean it would no long use the submit, therefore not execute the form action, therefore not sending the value of the selected.

 

Is there a onchange(this.selected) to send to a javascript function which will execute a php header:location with the correct variables in the url to get in the next page?

 

In short, I want you to click an option in the drop down and it takes you to the next page with that selected info.

Link to comment
Share on other sites

there is a need for a little bit of php which im not sure how to implement

 

i have this function that is excecuted onchange

 

function change()

{

var mylist=document.getElementById("myList")

var JSVar = mylist.options[mylist.selectedIndex].text

window.location = "http://www.4tenonline.com/newupdatetextarea.php?user=<?PHP $user ?>&pagechoice=JSVar" target="main"

}

 

 

2 questions

1: can i do that <?PHP $user ?>

2: (idk if you can answer this here) is that you how you include a javascript variable in a url? just the name of the variable &pagechoice=JSVar

Link to comment
Share on other sites

got it, woooo

 

I use onchange to execute a javascript function

that function used ID's to get the selected value and store it to a variable

Then i stored my PHP variable as a Javascript variable

Then created a variable string of the URL with the selected variable and PHP variable

then i used window.parent.framename.location to execute that variable string

Link to comment
Share on other sites

Sorry, apparently I was a day too late.  Your previous post was very close.  Yes, you can use <?php ?> tags anywhere.  However, you either need to use <?=$var; ?> or <?php echo $var; ?> in order to output the contents of a variable to the current page.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.