Jump to content

Recommended Posts

Hi there, I have a form in php where the user puts in a dienumber, number of peices,and the length of each cut. I need then to look up the weight of the die in a db then multiple that by the number of peices multiple the length, then output the answer in the kgs field, is this possible? Figured i would need the onChange and thus js. But my php is better than my js :S So far have this, think im nearly there(maybe?)
Thanks

echo '<script language="javascript">';
echo 'function Getweight(){';
echo 'peices = document.inputs.pieces.value;';
echo 'cutlength = document.inputs.cutlength.value;';
//need to look up weight of die
//need to output back to doc.inputs.kgs

echo '}';
echo '</script>';

echo '<FORM action="../update/updateOrdering.php" method="get" name="inputs">';
echo '<TD class="value"><INPUT type="text" name="dienumber" value="" maxlength="10" size="20"></TD>';
echo '<TD class="value"><INPUT type="text" name="pieces" value="2" maxlength="10" size="20"></TD>';
echo '<TD class="value"><INPUT type="text" name="cutlength" value="1" maxlength="10" size="20" onChange="Getweight()"></TD>';
echo '<TD class="value"><INPUT type="text" name="kgs" value="" maxlength="10" size="20"></TD>';
.....

select dieweight from die_tab where dienumb = 1234
Link to comment
https://forums.phpfreaks.com/topic/3443-js-and-form-help/
Share on other sites

[!--quoteo(post=346203:date=Feb 16 2006, 12:09 AM:name=ruddernz)--][div class=\'quotetop\']QUOTE(ruddernz @ Feb 16 2006, 12:09 AM) [snapback]346203[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Hi there, I have a form in php where the user puts in a dienumber, number of peices,and the length of each cut. I need then to look up the weight of the die in a db then multiple that by the number of peices multiple the length, then output the answer in the kgs field, is this possible? Figured i would need the onChange and thus js. But my php is better than my js :S So far have this, think im nearly there(maybe?)
Thanks

echo '<script language="javascript">';
echo 'function Getweight(){';
echo 'peices = document.inputs.pieces.value;';
echo 'cutlength = document.inputs.cutlength.value;';
//need to look up weight of die
//need to output back to doc.inputs.kgs

echo '}';
echo '</script>';

echo '<FORM action="../update/updateOrdering.php" method="get" name="inputs">';
echo '<TD class="value"><INPUT type="text" name="dienumber" value="" maxlength="10" size="20"></TD>';
echo '<TD class="value"><INPUT type="text" name="pieces" value="2" maxlength="10" size="20"></TD>';
echo '<TD class="value"><INPUT type="text" name="cutlength" value="1" maxlength="10" size="20" onChange="Getweight()"></TD>';
echo '<TD class="value"><INPUT type="text" name="kgs" value="" maxlength="10" size="20"></TD>';
.....

select dieweight from die_tab where dienumb = 1234
[/quote]

I'm a little confused by your post. If you're asking if you can send requests to a database with JS I'm afraid you can't.

Can't you submit the form, and then process the fields with PHP using $_GET['pieces'], etc, query the DB, make the calculations and then display a message to the user?

You don't really want js to take care of any essential functions because of the varying support and fact that some people disable it. When it comes to forms you're best to use JS for validation, but even then you have to double check on the server-side.
Link to comment
https://forums.phpfreaks.com/topic/3443-js-and-form-help/#findComment-11809
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.