Jump to content
  • 0

Using Java to Insert into Search Form


mdupras
 Share

Question

I'm struggling to figure out how I can use JavaScript to insert a value into a search form. What I'm trying to do is compare the current hour to a value in the table (current hour is greater than this field and less than this field, etc.) I can successfully grab the current hour, but I don't know how to pass that to be the search value.

Any ideas? Caspio has instructions on how to do that on a Details page, but it's not working on the search form.

-- Mike

Link to comment
Share on other sites

5 answers to this question

Recommended Posts

  • 0

Thanks, Barbara!

I know very little JavaScript, so I think I'm going to need more help! I follow the need to use \"Value1_1,\" etc., but I don't understand how to construct the code. Here's the best that I came up with:

currentTime = new Date();

currentHour = currentTime.getHours();

var field1 = \"Value3_1\";

var field2 = \"Value4_1\";

function checkTime()

{

var checkOpen = document.getElementsByName(field1);

var checkClose = document.getElementsByName(field2);

checkOpen[0].value=currentHour;

checkClose[0].value=currentHour;

}

onSubmit=checkTime;

This search and report is a very simple version of a larger restaurant database we're building. I'm testing the function of comparing the current time to restaurant open and close time so that it displays only restaurants open right now.

In this test, you can search by community name and type of cuisine. Those are the first two fields. The third and fourth fields are set to be hidden and are the hour the restaurant opens and the hour it closes, respectively. What I'm trying to do with the JavaScript is call up the current hour and insert it into those third and fourth fields on the search form, which would then compare them \"less than or equal to\" and \"greater than or equal to,\" respectively.

Make sense?

-- Mike

Link to comment
Share on other sites

  • 0

If I understand correctly this should be the javascript you need:

<script>
window.onload = function(){ 

currentTime = new Date(); 
currentHour = currentTime.getHours(); 

document.forms[0].Value3_1.value = currentHour; 
document.forms[0].Value4_1.value = currentHour;
}
</script>
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...