trying to do AJAX

J

jr

Is the code right? It is my first XMLHTTP. I am getting the id var
passed from php but I'm not sure about the nationalDrugCode var.
I have a question, even if I didn't get the value passed from php on
the ndc, it should echo get1 as id without the rest right? I'm not
getting anything echoed from the second alert. Is everything okay
with the SaveThisRecord dialog? If all goes well I just want it to run
the UPDATE php script to update the mysql db with the nationalDrugCode
value of the row with the record id of the id?
thanks,
<script type="text/javascript">
function saveRecord(id) {

alert(id);

var answer=confirm("Save this record?")
if(!answer){return;}
get1="id="+id;

get1+="&nationalDrugCode="+document.getElementByID("nationalDrugCode"
+ id).value;
alert(get1);

if ( window.XMLHttpRequest ) {// code for IE7+, Firefox, Chrome,
Opera, Safari
xmlhttp=new XMLHttpRequest();
}else{ // code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");

}
xmlhttp.open("GET","saveRecord.php?" + get1,true);
xmlhttp.send();
}
 
D

David Mark

Is the code right?

That's a rather open-ended question (and subject to interpretation).
It is my first XMLHTTP.

Congratulations! :)
I am getting the id var
passed from php but I'm not sure about the nationalDrugCode var.

What generates your code is of no interest. Lack of understanding of
your code is (and makes me think I am wasting my time looking at it).
I have a question, even if I didn't get the value passed from php on
the ndc,  it should echo get1 as id without the rest right?

I have no idea what that means.
I'm not
getting anything echoed from the second alert.

Okay, that's a good clue.
Is everything okay
with the SaveThisRecord dialog?
Dialog?

If all goes well I just want it to run
the UPDATE php script to update the mysql db with the nationalDrugCode
value of the row with the record id of the id?

Is that really a question?

You bet.
<script type="text/javascript">
        function saveRecord(id) {

            alert(id);

It would be helpful to know what you see alerted here.
            var answer=confirm("Save this record?")
                    if(!answer){return;}

I assume that's the "dialog" you referred to. Don't use questions
with confirm as the buttons are (usually) OK/Cancel. Use a statement
like "This action will save the record."
            get1="id="+id;

get1+="&nationalDrugCode="+document.getElementByID("nationalDrugCode"
+ id).value;

At a glance I'd guess you are bombing out here. You misspelled the
getElementById method for one. Are you using a debugger?
            alert(get1);

Next time post more information about what went wrong and the related
markup as well. How should anyone know what elements exist in your
document without seeing it?
 
J

jr

That's a rather open-ended question (and subject to interpretation).


Congratulations!  :)


What generates your code is of no interest.  Lack of understanding of
your code is (and makes me think I am wasting my time looking at it).


I have no idea what that means.


Okay, that's a good clue.


Is that really a question?


You bet.



It would be helpful to know what you see alerted here.




I assume that's the "dialog" you referred to.  Don't use questions
with confirm as the buttons are (usually) OK/Cancel.  Use a statement
like "This action will save the record."



At a glance I'd guess you are bombing out here.  You misspelled the
getElementById method for one.  Are you using a debugger?


Next time post more information about what went wrong and the related
markup as well.  How should anyone know what elements exist in your
document without seeing it?

thanks, it works now.
 
J

jr

That's a rather open-ended question (and subject to interpretation).


Congratulations!  :)


What generates your code is of no interest.  Lack of understanding of
your code is (and makes me think I am wasting my time looking at it).


I have no idea what that means.


Okay, that's a good clue.


Is that really a question?


You bet.



It would be helpful to know what you see alerted here.




I assume that's the "dialog" you referred to.  Don't use questions
with confirm as the buttons are (usually) OK/Cancel.  Use a statement
like "This action will save the record."



At a glance I'd guess you are bombing out here.  You misspelled the
getElementById method for one.  Are you using a debugger?


Next time post more information about what went wrong and the related
markup as well.  How should anyone know what elements exist in your
document without seeing it?

It is working now thanks very much. I do understand what it does.
The id is passed in the function from the html.It gets the correct row
of records by the id then saves the field ndc to mysql. What I don't
understand is the get1. I did borrow this code from a page at work by
another developer which is very similar to my app.

get1="id="+id;

if the assignment is on the getElementbyId line
get1+= which seems weird because += means something else usually

I guess it is building a string but it isn't clear to me exactly how.
 
A

Asen Bozhilov

jr said:
            var answer=confirm("Save this record?")
                    if(!answer){return;} ^^^
Missing semicolon. Even ES implementation has ASI use semicolon in
explicit way. It's good habit. Also you can use IDE which you suggest
where should be putted semicolon.
            get1="id="+id;

Declare first as local variable, before you assign a value. Now `get1`
is a property of Global Object. Is it expected behavior? I don't think
so according other parts of your code.
                if ( window.XMLHttpRequest ) {// code forIE7+, Firefox, Chrome,
Opera, Safari
                  xmlhttp=new XMLHttpRequest();
                }else{ // code for IE6, IE5
                  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");

                }

From where you get this? How did you assume if `window.XMLHttpRequest'
does not have value for which ToBoolean conversion is equal to `true'
there is `ActiveXObject' property of Global Object and value for that
property refer object, which has got [[Construct]] method?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,058
Latest member
QQXCharlot

Latest Threads

Top