Jump to content

Is there a way to enter the chosen form value, without having to submit first?


Morris2

Recommended Posts

 

Hello PHP world!

 

I have this roll-down-select-menu working, reflecting a column in my database.

I am able to retrieve the selected value after submit, that takes me to another code page.

 

But I would like to use this value on the form page, that contains the roll-down-menu and the submit button. Is there a way to enter the chosen value into this variable $uan, without having to submit the page first?

 

I tried to retrieve the value on this page with the POST lines at the button, but without luck.

I think the value is only entered upon submit?

 

Thanks in advance for your clever advice.

 

Best regards Morris

 

<?php

$query = "SELECT * FROM Uniq_artist_name" ;

$result = mysql_query($query);

echo'<select name="uan">';

while($row = mysql_fetch_assoc( $result )) {

        echo '<option value="'.$row['uniqartistname'].'">'. $row['uniqartistname'] .'</option>'; }

echo '</select>';

 

$uan = $_POST["uan"];

echo "$uan";

?>

Link to comment
Share on other sites

If you dont mind a page refresh, try adding this code to the select button (replacing my_page.php with your page url):

onChange="javascript: window.location = 'my_page.php?uan='+this.value;"

 

and at the top of the page add this:

 

<?php
if(isset($_GET["uan"]) &&$_GET["uan"] !='') {
$uan = $_GET["uan"];
}
?>

Link to comment
Share on other sites

 

Thanks for this.

 

I just tried this, debugger says:

 

unexpected T_STRING, expecting ',' or ';' in this line:

echo'<select name="uan"onChange="javascript: window.location = full_web_url_to_this_page?uan='+this.value;">';

 

Can't see whats wrong here.

 

Besides from that, did I undertand this right: full_web_url_to_this_page?uan

 

Is it possible to do this without updating the page?

 

Regards Morris

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.