Welcome to Dream.In.Code
Become an Expert!

Join 150,413 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 981 people online right now. Registration is fast and FREE... Join Now!




need help with a reloading select form

 
Reply to this topicStart new topic

need help with a reloading select form

arrifinu
17 Mar, 2008 - 04:54 AM
Post #1

New D.I.C Head
*

Joined: 31 Aug, 2007
Posts: 7


My Contributions
Hello everybody,
I wanna ask about how to keep a choice after the page loads

CODE
<head>
<meta http-equiv="refresh" content=";">
</head>
<body>
<font size="1"><b>Load Page</b></font><br>
    <form id="formmaz" name="formmaz" method="post">
    <select name="selectmaz" onchange="formmaz.submit()">
                <option value=" ">No Loading</option>
                <option value="60">1 minute</option>
                <option value="300">5 minutes</option>
                <option value="600">10 minutes</option>
                <option value="900">15 minutes</option>
    </select>
    <input type="hidden" name="MM_insertmaz" value="formmaz">
    </form>


To clarify my demande, lets say i want the page to load every 5 minutes, and i get in the form No Loading, and i choose from the form 5 minutes. The problem is that as soon as the page reloads the form regets No Loading as a message appearing, which means the page wont load anymore, while I want to keep my choice, so that it keeps loading every 5 minutes.

Is there anything to add to my code so that it saves and keeps my choice after loading the page??
I wish my demande is clear
waiting for your answer.
Thanks in advance

This post has been edited by arrifinu: 17 Mar, 2008 - 05:00 AM
User is offlineProfile CardPM
+Quote Post

thehat
RE: Need Help With A Reloading Select Form
17 Mar, 2008 - 06:35 AM
Post #2

D.I.C Head
Group Icon

Joined: 28 Feb, 2008
Posts: 217


Dream Kudos: 100
My Contributions
Is there any server code on your page that you've mentioned?

Assuming there's not, then if you change your form method to get rather than post your form values appear in the page url, like so: http://www.yourdomain.com/yourpage.html?selectmaz=60

You can set an item on your form as selected like this:
CODE

<head>
<meta http-equiv="refresh" content=";">
<script type="text/javascript">
//function returns values of GET variables
function getQueryVariable(variable) {
    var query = window.location.search.substring(1);
    var vars = query.split("&");
    for (var i=0;i<vars.length;i++) {
        var pair = vars[i].split("=");
            if (pair[0] == variable) {
            return pair[1];
        }
    }
}

//called on body load
function onPageLoad() {
    var targElement = document.formmaz.selectmaz;
    //set the selected index of the form
    switch(getQueryVariable("selectmaz")) {
        case "no":
            targElement.selectedIndex = 0;
            break;
        case "60":
            targElement.selectedIndex = 1;
            break;
        case "300":
            targElement.selectedIndex = 2;
            break;
        case "600":
            targElement.selectedIndex = 3;
            break;
        case "900":
            targElement.selectedIndex = 4;
            break;
    }
    
}
</script>
</head>
<!-- call onPageLoad when, you guessed it, the page loads -->
<body onload="onPageLoad()">
<font size="1"><b>Load Page</b></font><br>
    <form id="formmaz" name="formmaz" method="get">
    <select name="selectmaz" onchange="formmaz.submit()">
                <option value="no">No Loading</option>
                <option value="60">1 minute</option>
                <option value="300">5 minutes</option>
                <option value="600">10 minutes</option>
                <option value="900">15 minutes</option>
    </select>
    <input type="hidden" name="MM_insertmaz" value="formmaz">
    </form>

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 07:49PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month