Jump to content

PHP, jAVASCRIPT setting input values, why isn't it working?


iAIN mACfREAK

Recommended Posts

Hi:

 

I am calling this javascript:

<script language="javascript">

function set_item_values(x)

{

document.forms.form1.GetElementById(x).value = "itemcode";

}

 

</script>

 

 

 

from here, to set other values in the form:

  <select name="Product_Pick" size="1" id="Product_Pick" onchange="set_item_values(document.forms.form1.Item_Code)">

    <?php

do { 

?>

    <option value="<?php echo $row_Product_Select['Product_Code']?>"><?php echo $row_Product_Select['Product_Code']?> - <?php echo $row_Product_Select['Name']?></option><?php

} while ($row_Product_Select = mysql_fetch_assoc($Product_Select));

  $rows = mysql_num_rows($Product_Select);

  if($rows > 0) {

      mysql_data_seek($Product_Select, 0);

  $row_Product_Select = mysql_fetch_assoc($Product_Select);

  }

?>

 

The value I have in there so far is just a proving string...

 

It ain't working, but I don't know why, and I am having problems finding a good reference for using php and javascript for working with documents and events in html, so that i can set off a value change to set values for several fields, or perform actions.

 

Can I have my hand held please and someone get me up and running?  I have been programming for 15 years or so and in different languages (from pl1, jcl, pascal, to basic, java) so what I guess a good insight into using variables and syntax would get me going...

you cannot execute php inside javascript like that.  php is a server-side language, parsed on the server.  javascript is a client-side language, parsed client-side.  One is just plain text to the other, and visa versa.  In order to get javascript to execute php, you have to use ajax, which is a javascript method of sending a request to the server and receiving a response.  There are tons of ajax tutorials out there to get you started.

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.