...

View Full Version : client side refresh using JavaScript



splashedwater
10-28-2004, 09:54 PM
Hi guys,

I have coded a page using a mixture of PHP, MYSQL, HTML. Basically it is a form where the user makes a selections from a series of radio buttons, everytime the user makes a selection it updates the total, pretty simple. The problem is the refresh is way to long for every item selected, I've heard using javascript you can nearly eliminate the refresh time by making the code execute client side. I cannot find any books, guides, or sample code related this particular problem. Help would be greatly appreciated. Thanks.

mcdougals4all
10-28-2004, 10:24 PM
Javascript makes use of event handlers that often make it unnecessary to do any type of refresh when reacting to user input.

Here's a quick example:


<form>
<label for="yes">Yes</label><input name="pick_one" type="radio" value="Yes" id="yes" onclick="alert('You clicked yes!');">
<label for="no">No</label><input name="pick_one" type="radio" value="No" id="no" onclick="alert('You clicked no!');">
</form>


To elaborate, you could total your user's input by replacing the alert with a calculation function relevant to what you're doing.

For more info, here's a link (http://www.w3schools.com/dhtml/dhtml_events.asp) to get you going.

And welcome to the forums. :)

splashedwater
10-29-2004, 12:01 AM
Thanks for the help. Event handlers are awesome, these should work perfectly. Now I have a very "newb" question. What is the propper syntax for printing my variables(.$Warranty) value($100) using event handlers in javascript? I see ways of using alerts, and changing the color of things. But cannot find the syntax to just print and add together values (everytime the user selects a new radio box in a section, it needs to add to the previouse radio boxes selected). Is this even possible using even handlers? Thanks again! :)


<form>
<label for="yes">Yes</label><input name="pick_one" type="radio" value="Yes" id="yes" onclick="alert('You clicked yes!');">
<label for="no">No</label><input name="pick_one" type="radio" value="No" id="no" onclick="alert('You clicked no!');">
</form>

splashedwater
10-29-2004, 12:02 AM
Ignore the code below my last post. I did not mean to repost the code. Oops :)

splashedwater
10-30-2004, 05:47 PM
Actually that worked great. I I'm not completely done now, but I'm well on my way. Thanks a ton!!!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum