Forum Moderators: open

Message Too Old, No Replies

Null value validation

         

CoderRee

6:44 am on May 5, 2008 (gmt 0)

10+ Year Member



function processPoll() {
if (req.readyState == 4) { // Complete
if (req.status == 200) { // OK response
var message = req.responseXML.getElementsByTagName("message")[0];
var value= message.childNodes[0].nodeValue;

if(value=='valid'){
alert('Poll submitted successfully');
}
else{
alert('Poll already submitted');
}
refreshSection('2');
} else {
alert("Problem with server response:\n " + req.statusText);
}
}
parent.frames[2].name="main";
}

I have called the above function on :
req.onreadystatechange = processPoll;

This is a validation done for Submitting a poll after selecting the option. It works perfectly as per my requirement. The only problem is even if I click on the 'submit poll' button without choosing any option it will show "Poll Submitted Successfully" but with no change in the graph or values. So, my requirement is a condition which gives an alert as to "Please make a Selection" when clicked on "Submit Poll" button.

The graph/values are read from XML and on submit, the values are written into XML

My brains are shut off at present and i hope someone will be able to help. Thanks in advance.

httpwebwitch

7:24 pm on May 5, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



sounds like you need an onclick event on your button, which returns false if no option is selected.

<input type="button" onclick="return optionIsSelected()" value="Submit Poll" />

where optionIsSelected() is a function which returns true if an option is selected, false otherwise.

CoderRee

5:15 am on May 6, 2008 (gmt 0)

10+ Year Member



<input type="button" value=" Submit Poll "onclick="retrievePoll('HomePage_pollSave.action?','HomeForm');" />

/*
** retrievePoll() validation is in Ajax
*/

function retrievePoll(url,nameOfFormToPost) {

//get the (form based) params to push up as part of the get request
try {
/*****
At the time of inserting the same poll option Cache object does'nt refresh,
so Math.random() function is used
****/

url=url+getPollFormAsString(nameOfFormToPost)+'&xde='+Math.random();

} catch (e) {
alert('bean problem');
}
//Do the Ajax call
if (window.XMLHttpRequest) { // Non-IE browsers
req = new XMLHttpRequest();
req.onreadystatechange = processPoll;
try {
req.open("GET", url, true); //was get
} catch (e) {
alert("Problem Communicating with Server\n"+e);
}
req.send(null);
} else if (window.ActiveXObject) { // IE

req = new ActiveXObject("Microsoft.XMLHTTP");
if (req) {
req.onreadystatechange = processPoll;
req.open("GET", url, true);
req.send();


}
}

}

and then the above function of processPoll() is called !

Something is missing in processPoll() function. I just cant think of it ...........................