www.webdeveloper.com
Results 1 to 8 of 8

Thread: Posted Code for my previous message asking for help with submitting variables

  1. #1
    Join Date
    Jan 2004
    Posts
    5

    Posted Code for my previous message asking for help with submitting variables

    Here is the code for the topFrame:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>CoralSoft Systems Time Electronic Timesheet</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script language="JavaScript">
    var employee=new Array(7);
    employee[0]=new Array("BROOKE","ERROL","PAM","GARY");
    employee[1]=new Array("Web Programmer","Software Engineer","Database Architect","IT Specialist");
    employee[2]=new Array(30.00,60.00,50.00,40.00);
    employee[3]=new Array(4);
    employee[4]=new Array(4);
    employee[5]=new Array(4);
    employee[6]=new Array(4);



    function calculate(form){
    var weekend=0;
    var week=0;
    var overtime=0;

    for(i=0; i<7; i++){
    if(hours[0][i]=="sun" || hours[0][i]=="sat"){
    weekend=weekend+hours[1][i];
    }//close if
    else if(hours[0][i]=="mon" || hours[0][i]=="tues" || hours[0][i]=="wed" || hours[0][i]=="thurs" || hours[0][i]=="fri"){
    week=week+hours[1][i];
    }//close else
    }//close for

    if(week>40){
    overtime=(week-40);
    week=40;
    }//close if

    alert("Week hours is: " + week);
    alert("Weekend hours are: " + weekend);
    alert("Overtime is: " + overtime);


    var pay=parseInt(form.payrate.value);
    var regpay;
    var weekendpay;
    var overtimepay;
    var total;

    regpay=(week*pay);
    form.regpay.value=regpay;
    alert("Regular Pay is: " + regpay);
    weekendpay=(weekend*(pay*2));
    form.weekendpay.value=weekendpay;
    alert("Weekend pay is: " + weekendpay);
    overtimepay=(overtime*(pay*1.25));
    form.overtimepay.value=overtimepay;
    alert("Overtime pay is: " +overtimepay);
    total=(regpay+weekendpay+overtimepay);
    form.totalpay.value=total;
    alert("Total pay is: " + total);

    form.target="bottomFrame";
    form.submit();
    return true;
    }//close function


    </script>
    </head>

    <body>
    <form name="timesheet" method="link" action="mainPage.htm" >
    <input name="payrate" value="" type="hidden">
    <input name="regpay" value="" type="hidden">
    <input name="weekendpay" value="" type="hidden">
    <input name="overtimepay" value="" type="hidden">
    <input name="totalpay" value="" type="hidden">


    <table align="center">
    <tr>
    <td>Name:</td>
    <td><input name="name1" value="" type="text" onChange="checkName(this);"></td>
    </tr>
    <tr>
    <td>Department:</td>
    <td><select name="dept">
    <option value="pick" selected>-Select a Department</option>
    <option value="hr">Human Resources</option>
    <option value="acct">Accounting</option>
    <option value="is">Information Systems</option>
    </select></td>
    </tr>
    <tr>
    <td>Position Title:</td>
    <td><input name="job" value=""></td>
    </tr>
    </table>
    <br><br><br><br><br><br>
    <table align="center">
    <tr>
    <td>Sunday</td>
    <td>Monday</td>
    <td>Tuesday</td>
    <td>Wednesday</td>
    <td>Thursday</td>
    <td>Friday</td>
    <td>Saturday</td>
    </tr>
    <tr>
    <td><input name="sun" value=0 onChange="addHour(this);"></td>
    <td><input name="mon" value=0 onChange="addHour(this);"></td>
    <td><input name="tues" value=0 onChange="addHour(this);"></td>
    <td><input name="wed" value=0 onChange="addHour(this);"></td>
    <td><input name="thurs" value=0 onChange="addHour(this);"></td>
    <td><input name="fri" value=0 onChange="addHour(this);"></td>
    <td><input name="sat" value=0 onChange="addHour(this);"></td>
    </tr>
    </table>
    <br><br><br><br><br>
    <table align="center">
    <tr>
    <td><input name="store" type="button" value="Store Info." onClick="storeAll(this.form);"></td>
    <td><input name="res" type="reset" value="Reset Time Card"></td>
    <td><input name="show" type="button" value="Show All"></td>
    <td><input name="calc" type="button" value="Calculate Pay" onClick="calculate(this.form);"></td>
    </tr>
    </table>
    </form>
    </body>
    </html>

    it's a lot to go through...I'm sorry. The function that calls the code that is supposed to submit the info. is the calculate() function which I called using calculate(this.form).

  2. #2
    Join Date
    Jan 2004
    Location
    Washington DC
    Posts
    1,107

    First off

    You haven't assigned anything to the "form" variable that you are using to attribute to the form elements. You need to specify that first:

    Code:
    var form=document.forms[0];
    and let me gues, you get an "Object expected" error

  3. #3
    Join Date
    Jan 2004
    Posts
    5
    Form is actually sent via the calling entity:

    onClick=calculate(this.form) is sent and the function catches it as:

    calculate(form) and it is using the instance of form that is sent. I'm not getting an error on the frame. What is happening is that I am using the window.location variable in the form that is supposed to receive the form, but it only receives the URL...not the data from the form variables. Any other ideas?

  4. #4
    Join Date
    Jan 2004
    Location
    Washington DC
    Posts
    1,107

    Here's an oops

    Code:
    <form method="link"
    is invalid

    they are: GET and POST

  5. #5
    Join Date
    Jan 2004
    Posts
    5
    I'm 2 seconds from giving up...I changed it to post and that didn't work either. So, what I did was I wrote a small prototype program of the program that I'm trying to complete. This is what my main frame page looks like:

    <html>
    <head>
    <title>Untitled Document</title>
    </head>
    <frameset cols="50%,50%">
    <frame name="rightFrame" src="test1.htm">
    <frame name="leftFrame" src="test2.htm">
    </frameset><noframes></noframes>
    </html>

    Then I have the two source pages. When I open this main page, and onSubmit() is called...3 frames open up. 2 are duplicates....and no data is sent. I am truly baffled...here are the other two source codes:

    test1:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

    <script language="JavaScript">

    function sendInfo(form){
    form.target="leftFrame";
    form.submit();
    return true;
    }

    </script>
    </head>

    <body>
    <form name="fred" method="post" action="maintest.htm">
    <input name="test1" type="text" value="">
    <input name="test2" type="text" value="">
    <input name="sendit" type="button" onClick="sendInfo(this.form);">
    </form>
    </body>

    and test2:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script language="JavaScript">
    var locate = window.location;
    alert(locate);
    document.write(locate);
    //document.fred.temp.value = locate;
    //var text = document.fred.temp.value
    var text;
    function delineate(str){

    theleft = str.indexOf("=") + 1;
    theright = str.indexOf("&");
    if(theright==-1){
    theright=theleft+str.length+1
    return(str.substring(theleft, theright));
    }
    else{
    text=str.substring(theright+1,str.length);
    return(str.substring(theleft, theright));
    }
    }


    function init(){
    document.fred.temp.value = locate;
    text = document.fred.temp.value
    alert(text);
    var temp_num;
    temp_num= delineate(text);
    document.fred.info1.value= temp_num;
    temp_num = delineate(text);
    document.fred.info2.value= temp_num;


    }
    </script>
    </head>

    <body>
    <form name="fred" onLoad="init();">
    <input name="temp" value="" type="hidden" size=100>
    <input name="info1" value="">
    <input name="info2" value="">
    </form>
    </body>
    </html>

    I'm drowning here guys....I'm not a guru....I'm completely baffled.

  6. #6
    Join Date
    Jan 2004
    Location
    Washington DC
    Posts
    1,107

    Passing values

    Are you trying to pass the values in a querystring? If so, your form method should be GET not POST

  7. #7
    Join Date
    Jan 2004
    Posts
    5
    So...how about this question. I have now used "get" as my form method....BUT now I can't figure out how to get the variables once I have passed them in the query string. I was thinking that I should use window.location and that should have the url of the passing frame and the form variables...but that's not working either....any gurus got ideas?

  8. #8
    Join Date
    Jan 2004
    Location
    Washington DC
    Posts
    1,107

    script

    this will parse your querystring
    Code:
    <script>
    
    var query=document.location.search;
    
    query=query.replace(/^\?/,"");
    
    varray=query.split("&");	    
    
    var get=Array();
    
    for(i=0;i<varray.length;i++){
    	temp=varray[i].split("=");
    	get[temp[0]]=temp[1];
    }
    
    	
    document.write(get["home"]);
    
    </script>
    Each variable is stored in the get[] array. Just include the variable name i the get[] to get the value.

    You can also do this processing on the server.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles