Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
BOOK: Professional Ajax ISBN: 978-0-471-77778-6
This is the forum to discuss the Wrox book Professional Ajax by Nicholas C. Zakas, Jeremy McPeak, Joe Fawcett; ISBN: 9780471777786
Important: For the new 2nd edition of this book, please post here instead: [url="http://p2p.wrox.com/forum.asp?FORUM_ID=307"]http://p2p.wrox.com/forum.asp?FORUM_ID=307[/url]
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional Ajax ISBN: 978-0-471-77778-6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old December 5th, 2007, 09:41 PM
Registered User
 
Join Date: Dec 2007
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Zxml.js and input radio problem

Hi everyone.

I use zxml.js on many projects and it works great. But now I suddenly used it with <input type="radio" /> and I don't know how to solve the puzzle =)

When I submit the form, zxml.js sends a request with sumthing like this:

bg=0&bg=1&stroke=0&stroke=1&stroke=2&stroke=3

As you see I have 2 radios named "bg" and 4 named "stroke". I supposed that the result of form submission wolud be only the selected radios. Not all ptesented on the page.

Please help. I gotta have only the selected radios =) In example bg=1&stroke=2

Thanks ahead.

  #2 (permalink)  
Old December 6th, 2007, 06:51 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

I don't think zXml is to blame, can you show the actual form and how you are posting the data?

--

Joe (Microsoft MVP - XML)
  #3 (permalink)  
Old December 6th, 2007, 08:40 AM
Registered User
 
Join Date: Dec 2007
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for response.

For a simple example I take the code from HTML 4.01 Spec:

<FORM action="http://somesite.com/prog/adduser" method="post">
    <P>
    First name: <INPUT type="text" name="firstname"><BR>
    Last name: <INPUT type="text" name="lastname"><BR>
    email: <INPUT type="text" name="email"><BR>
    <INPUT type="radio" name="************" value="Male"> Male<BR>
    <INPUT type="radio" name="************" value="Female"> Female<BR>
    <INPUT type="submit" value="Send"> <INPUT type="reset">
    </P>
</FORM>


Then I added some code so that it worked without refresh.

<form method="post" name="form" id="form" onsubmit="sendRequest(this.id); return false;" action="test.html">
    <P>
    First name: <INPUT type="text" name="firstname"><BR>
    Last name: <INPUT type="text" name="lastname"><BR>
    email: <INPUT type="text" name="email"><BR>
    <INPUT type="radio" name="************" value="Male"> Male<BR>
    <INPUT type="radio" name="************" value="Female"> Female<BR>
    <INPUT type="submit" value="Send"> <INPUT type="reset">
    </P>
</FORM>
<p id="reform">&nbsp;</p>


Of course Zxml.js id implied and I added some JS.

function sendRequest(fId) {var oForm = document.getElementById(fId);var sBody = getRequestBody(oForm);var oXmlHttp = zXmlHttp.createRequest();oXmlHttp.open("post", oForm.action, true);oXmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");oXmlHttp.setRequestHeader("Charset", "windows-1251");oXmlHttp.onreadystatechange = function () {if (oXmlHttp.readyState == 4) {if (oXmlHttp.status == 200) {saveResult(oXmlHttp.responseText, oForm);} else {saveResult("Error: " + oXmlHttp.statusText, oForm);}}};oXmlHttp.send(sBody);}

function getRequestBody(oForm) {var aParams = new Array();for (var i=0 ; i < oForm.elements.length; i++) {var sParam = encodeURIComponent(oForm.elements[i].name);sParam += "=";sParam += encodeURIComponent(oForm.elements[i].value);aParams.push(sParam);}return aParams.join("&");}

function saveResult(sMessage, ooo) {var divStatus = document.getElementById('re' + ooo.id);divStatus.innerHTML = sMessage;}


In the test.html file I just print all the posted form elements by server-side script. It show relevant vars for input.text, input.select etc. But not for radios — it's always a first input.radio.value in the form. That's because it get it from the request I showed above.

  #4 (permalink)  
Old December 8th, 2007, 05:19 PM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

When a form is submitted naturally then only the names of the radio buttons that are selected are sent along with their values or "on" as a default.

Your code just loops through them all and sends the value, if you want to imitate a submission then you must verify if they're checked before including them in sMessage.

--

Joe (Microsoft MVP - XML)


Similar Threads
Thread Thread Starter Forum Replies Last Post
zxml.js errors? Richard Frainier BOOK: Professional Ajax ISBN: 978-0-471-77778-6 4 April 13th, 2015 01:57 AM
zxml.js library for firefox 3.0 manahual BOOK: Professional Ajax ISBN: 978-0-471-77778-6 4 March 2nd, 2010 04:59 AM
zxml.js - is there a readable copy available? bobwazz BOOK: Professional Ajax ISBN: 978-0-471-77778-6 3 May 17th, 2007 09:21 AM
syntax error only when zxml.js included daddy BOOK: Professional Ajax ISBN: 978-0-471-77778-6 1 July 1st, 2006 10:33 PM
MSXML 6 in zxml.js rloewy BOOK: Professional Ajax ISBN: 978-0-471-77778-6 1 May 2nd, 2006 02:23 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.