Forum Moderators: phranque

Message Too Old, No Replies

If statements within Web Form?

         

Makaveli

4:40 pm on Feb 7, 2006 (gmt 0)

10+ Year Member



Hello,

I was just wondering if anybody can help me out. I have an html webform that takes orders on my website.

I was just wondering if there is anyway to call out if statements from this webform.

For example if somebody were to type in the SKU of a product in the sku field of the form and the price of that SKU would automatically appear in the Price field of the web form.

Is there anyway this can be done via Javascript or php? Right now my form is actually in HTML however the action script file it's calling is a php file.

Anyhelp is appreciated.

Thanks in advance.

txbakers

4:46 pm on Feb 7, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



it can be done client side with JavaScript, but that is risky to rely on that.

To have the script do it server side would require a submit after each process, which could take some time.

It's a trade off.

Makaveli

4:34 pm on Feb 8, 2006 (gmt 0)

10+ Year Member



Hey txbakers,

Thanks for the reply.

Why do you say Javascript would be risky?

txbakers

4:47 pm on Feb 8, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



many people have it disabled, and you can only fire the function on an event - such as a change in the position of the drop down list for example.

SO, if a person loads a page, and they make their first selection, you can read their chnge, and do something.

If they don't do something on the screen, it won't cause the event to fire. And if they submit, you won't get the results intended.

I ran into this for a similar situation. I had a list of contests and the values of the drop down list were contestname:contestdate:deadline (with the colons)

As they changed the list to their contest, it would read the new value, and parse the three parts so I could check the deadline date against today using a client-side javascript. It worked fine for a while, until people starting just clicking the back button with that contest already loaded and not "changed to".

So many late entries were made.

I changed it to a server side process so that the value is only the ID number of the contest. When they submit, before any processing takes place I do a query of that contest ID and get the deadline date, then compre it to today, and if late, don't make the entry. It takes a little longer (a round trip to the server and an extra query) but my results are much more accurate.

Client Side javascript is good, but not foolproof. And there are a lot of fools out there.

Iguana

4:52 pm on Feb 8, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you are going to try the Javascript route (taking txb's comments into account) then have a look for "Remote scripting with IFrames" - it's a good article that can form the basis for the method. However, the example code does need some work to make it production quality.

dmmh

4:55 pm on Feb 8, 2006 (gmt 0)

10+ Year Member



or you could use AJAX :)

Iguana

5:17 pm on Feb 8, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Does AJAX work with old browsers - the IFrame method does. Also does AJAX use the MSXML component for it's remote access? There may be issues with the latest version of that component (SP2) because the security model has changed and cross-domain communication has been restricted.

dmmh

5:12 pm on Feb 11, 2006 (gmt 0)

10+ Year Member



a lot of people arent gonna agree with me on this I think, but I think striving to support all older browsers is a bit outdated, most people have already moved along anyway, so spending loads of time on developing everything cross-browser AND support all older versions for those browser imo isnt worth the small benefit