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";

?>

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"];
}
?>

 

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.