Jump to content

Recommended Posts

from the title this may sound simple. and to be honest i am a complete newb to JS and i have been redirected here by someone in the php section

 

but i have my form and everything works perfectly.

i want to add a new feature in.

 

my form is a booking form where a user can book an activity.

i have it linked to a mysql database so that there is a combo box with the titles of the activites, also in the table is the price of the activity.

what i want to happen is when the user selects one of the activities i want the price for that particular activity to be shown in a non-editable input box so that it can be passed onto the email send script. any ideas on how i can do this?

 

also i want something for a date selector.

since there are not the same amount of days in each month i want my form to be able to determine what month the user selected and then the right amount of days show in the day combo box.

for example if the user selects february in the month box, the day list should only go up to 28. then maybe when the user selects 2008 (the next year to be a leap year) the days in feb goes up to 29. suggestions would be awesome!

 

thanks for reading!

Link to comment
https://forums.phpfreaks.com/topic/60802-forms/
Share on other sites

what i want to happen is when the user selects one of the activities i want the price for that particular activity to be shown in a non-editable input box

 

Do you mean you want this price to be in a hidden input? Or do you wish to show the costumer the price of an activity? If you just want to show it you shouldn't use an input tag for security reasons

Link to comment
https://forums.phpfreaks.com/topic/60802-forms/#findComment-302613
Share on other sites

if your using your page for commercial goals i seriously recommends you don't pass the price to another page using a hidden input or normal input since anyone can just alter the price by saving the page to their drive and post different value's. I know for sure that i could do every activity for free then.

 

But anyway to your problem. to show the price in a div when you selected a activity from the selectbox without refreshing the page you can use the following code. It's just a little something that gets you on your way. You will need to follow an ajax tutorial to complete the code which there are plenty of online even on phpfreaks.com.

 

Read the comments how it works it should be a good start

<script>
function getPrice(activityValue){
//in this function you will have to do a call to an external AKA ajax that gets the price
//alert(activityValue);

//this is how to set the html inside the price_div
document.getElementById('price_div').innerHTML=activityValue;
}
</script>
<br />

<select onchange="getPrice(this.value)">
<option value="1">activity 1</option>
<option value="2">activity 2</option>
<option value="3">activity 3</option>
</select>
<br />
<b>function will place the value inside the following div</b>
<div style="heigth:20px;width:100px;border-width:1px;border-color:#000000;border-style:solid;" id="price_div">
 
</div>

Link to comment
https://forums.phpfreaks.com/topic/60802-forms/#findComment-302887
Share on other sites

well the user is not going to pay online this justs sends an email to my clientalerting him that someone wishes to book this activity, its more for convenience sakes than anything. it saves my client having to find out the price of the activity himself. but thatnks for the advice. ill have a look and see how i get on with it

Link to comment
https://forums.phpfreaks.com/topic/60802-forms/#findComment-303162
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.