View Single Post
Old 08-12-2007, 04:56 AM   PM User | #17
rwedge
Regular Coder

 
Join Date: Feb 2005
Posts: 679
Thanks: 0
Thanked 16 Times in 15 Posts
rwedge is on a distinguished road
Wanted to repost as I had a useless extra 'q'
Code:
<script type="text/javascript">
            var xmlHttp
            function GetXmlHttpObject(){
                try{
                    xmlHttp=new XMLHttpRequest();
                }
                catch (e){
                    try{
                        xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
                    }
                    catch (e){
                        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
                    }
                }
                return xmlHttp;
             }
             function stateChanged () {
                 if (xmlHttp.readyState == 4) {
                      if (xmlHttp.status == 200) {
                        alert('Good Response : '+xmlHttp.responseText);
                   } else {
                        alert('Error : '+xmlHttp.statusText);
                     }
                 }
             }
             function addcomment(name,comment,str){
             var q, url = (name || comment)? 'add_comment.php':'add_user_rating.php';
              q = (typeof name != 'undefined')? '?name='+escape(name):'?name='
              if(comment) q+='&comment='+escape(comment) // required entry
              else if (str) q='?rating='+str
              else { alert('Did you forget to enter a comment"');
              return;
             }
              // alert(url+q);  // uncomment to check
              xmlHttp=GetXmlHttpObject()
              if (!xmlHttp){
                   alert("Your browser doesn't support the technology required for this function.")
                   return
               }
              xmlHttp.onreadystatechange=stateChanged
              xmlHttp.open("GET",url+q,true)
              xmlHttp.send(null)
          }
        </script>



<form id="f"  action="" onsubmit="return false">
<p>name:<br />
<input type="text" id="name" value="" size="" maxlength="60" /></p>
<p>Comments:<br />
 <textarea id="comment" cols="25 rows="5" /></textarea></p>
<p>
<select id="rating" size="1" onchange="addcomment('','',this.options[this.selectedIndex].value)">
<option id="a" value="1">1</option>
<option id="b" value="2">2</option>
<option id="c" value="3">3</option>
</select> Rating</p>
<input type="button" id=".btn" value="Submit" onclick="addcomment(form.name.value,form.comment.value,'')" />
</form>
rwedge is offline   Reply With Quote