SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: Simple help

  1. #1
    ********* Wizard silver trophy Cam's Avatar
    Join Date
    Aug 2002
    Location
    Burpengary, Australia
    Posts
    4,495
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)

    Simple help

    Hey all,

    I have this form
    HTML Code:
    <form method='post'>
    <fieldset>
    	<legend align='center'>Test Form</legend>
    	
    	<label for='id'>ID:</label>
    	<input type='text' id='id' name='id' style='width: 30px;' /><br />
    	
    	<label for='field1'>Field 1:</label>
    	<input type='text' id='field1' name='field1' style='width: 150px;' /><br />
    	
    	<div>
    		<span style='float: left;'><input type='submit' name='save' value='Save All' /></span>
    		<span style='float: right;'><input type='button' value='<' onClick="moveRecord('prev', this.form.rec_id, this.form)" />&nbsp;<input type='button' value='>' onClick="moveRecord('next', this.form.rec_id, this.form)" /></span>
    	</div>
    </fieldset>
    </form>
    with this Javascript
    Code:
    <script type='text/javascript'>
    var records = new Array(3)
    	records[0]["id"] = '1';
    	records[0]["field1"] = 'blah1';
    	records[1]["id"] = '2';
    	records[1]["field1"] = 'blah2';
    	records[2]["id"] = '3';
    	records[2]["field1"] = 'blah3';
    	
    var index = 0;
    	
    	function moveRecord ( sTo, oForm ) {
    		document.getElementById('debug').innerHTML = sTo+"<br />"+parseInt(index)+"<br /><br />"; // debugging
    		
    		records[iFrom]["id"] = oForm.id.innerText;
    		records[iFrom]["field1"] = oForm.field1.innerText;
    		
    		index = ( sTo == 'next' ? parseInt(index) + 1 : parseInt(index) - 1 );
    		
    		document.getElementById('debug').innerHTML += parseInt(index) // debugging
    	
    		oForm.id.innerText = records[index]["id"];
    		oForm.field1.innerText = records[index]["field1"];
    		
    		return( true );
    	}
    </script>
    But it's not working The output in the debug DIV is this
    next
    NaN
    It'll say either next or prev, whichever button is pressed.

    Thanks for any help getting this to work

  2. #2
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why don't you tell us what it should do. I mean, I could guess, but I could be wrong.
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  3. #3
    SitePoint Guru Vincent Puglia's Avatar
    Join Date
    Feb 2000
    Location
    where the World once stood
    Posts
    700
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    If the following is not a typo, where is the 'debug' div?

    document.getElementById('debug').



    Vinny
    Where the World Once Stood
    the blades of grass
    cut me still

  4. #4
    ********* Wizard silver trophy Cam's Avatar
    Join Date
    Aug 2002
    Location
    Burpengary, Australia
    Posts
    4,495
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by beetle
    Why don't you tell us what it should do. I mean, I could guess, but I could be wrong.
    I have PHP write the Javascript array from a database, then the JS function is supposed to be so I can move through the records without talking to the server, updating as we go, and then when I click the Save All button, it will convert the JS array back to PHP and update the database.

    Quote Originally Posted by Vincent Puglia
    If the following is not a typo, where is the 'debug' div?
    I didn't include it in the code but it's just like this.
    HTML Code:
    <div id='debug'></div>
    Thanks for any help

  5. #5
    SitePoint Guru Vincent Puglia's Avatar
    Join Date
    Feb 2000
    Location
    where the World once stood
    Posts
    700
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    1) you didn't really answer Beetle's question
    2) you are sending 3 parameters (a switch, a record id, and the form object)

    moveRecord('prev', this.form.rec_id, this.form



    but...only asking for and naming 2:
    function moveRecord ( sTo, oForm )


    Since the parameters received are the switch and the record id, you have no form object with which to work.

    finally, you go on and use the record id you don't have (iFrom):

    records[iFrom]["id"] = oForm.id.innerText;



    Vinny
    Where the World Once Stood
    the blades of grass
    cut me still


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •