function createInnerHTML - how to repeat with other form input? - forms

I have the below code;
.gs
function createInnerHTML() {
var ss = SpreadsheetApp.getActive();
var names = ss.getSheetByName("WELD DATE LOG");
var namesValues = names.getRange(2,13,names.getLastRow()-1).getValues();
var innerHTML = [];
for (var i=0;i<namesValues.length;i++){
innerHTML.push({value:''+ namesValues[i][0], text:namesValues[i][0]});
};
return innerHTML;
}
.html
<? var innerHTML= createInnerHTML(); ?>
<select name="JOINT" id="JOINT" aria-label="JOINT" aria-required="true" required="">
<option value=""></option>
<? innerHTML.forEach(function(option) { ?>
<option value="<?= option.value ?>"><?= option.text ?></option>
<? }); ?>
</select>
The purpose is to update the form options by a column in the spreadsheet where I have some related issues:
First, if the cell is blank, I need to remove the option from the form because it reads a blank option in the list
For example, when a user opens the options list in the form, it gives 4 options with two are blank and two with values instead of displaying the two values only
Second, how can I repeat the same function in the same script but with other form questions whether select or checkbox
For example, I have this html form with two input fields:
<? var innerHTML= createInnerHTML(); ?>
<select name="JOINT" id="JOINT" aria-label="JOINT" aria-required="true" required="">
<option value=""></option>
<? innerHTML.forEach(function(option) { ?>
<option value="<?= option.value ?>"><?= option.text ?></option>
<? }); ?>
</select>
<select name="WS" required>
<option value=""></option>
<option value="WS S01">WS S01</option>
<option value="WS S02">WS S02</option>
<option value="WS S03">WS S03</option>
<option value="WS S04">WS S04</option>
</select>
In the .gs file, I need to repeat the same mentioned function "function createInnerHTML()" with both form inputs
Thanks in advance

if the cell is blank If the cell is blank can be corrected several ways. You could use the filter method on innerHTML or:
function createInnerHTML() {
var ss = SpreadsheetApp.getActive();
var names = ss.getSheetByName("WELD DATE LOG");
var namesValues = names.getRange(2,13,names.getLastRow()-1).getValues();
var innerHTML = [];
for (var i=0;i<namesValues.length;i++){
if(namesValues[i][0]) {
innerHTML.push({value:''+ namesValues[i][0], text:namesValues[i][0]});
}
};
return innerHTML;
}
how can I repeat the same function in the same script but with other form questions whether select or checkbox
You didn't supply any form information or spreadsheet data, so we don't really know the specifics to answer the question intelligently. Please provide additional information and code requirements.
This is how I generally update a select:
gs:
function getSelectOptions() {
sortOptions();
var ss=SpreadsheetApp.openById(getGlobal('gSSID'));
var sh=ss.getSheetByName('Options');
var rg=sh.getDataRange();
var vA=rg.getValues();
var options=[];
for(var i=0;i<vA.length;i++)
{
options.push(vA[i][0]);
}
return vA;
}
function sortOptions() {
var ss=SpreadsheetApp.openById(getGlobal('gSSID'));
var sh=ss.getSheetByName('Options');
var rg=sh.getRange(2,1,sh.getLastRow()-1,1);
rg.sort({column:1,ascending:true});
}
js:
function updateSelect(vA,id){
var id=id || 'sel1';
var select = document.getElementById(id);
select.options.length = 0;
for(var i=0;i<vA.length;i++)
{
select.options[i] = new Option(vA[i],vA[i]);
}
}

Okay I tried the below codes and they worked:
.html
<? var innerHTML= createInnerHTML1(); ?>
<select name="List1" required="">
<option value=""></option>
<? innerHTML.forEach(function(option) { ?>
<option value="<?= option.value ?>"><?= option.text ?></option>
<? }); ?>
</select>
<? var innerHTML= createInnerHTML2(); ?>
<select name="List2" required="">
<option value=""></option>
<? innerHTML.forEach(function(option) { ?>
<option value="<?= option.value ?>"><?= option.text ?></option>
<? }); ?>
</select>
.gs
function createInnerHTML1() {
var ss = SpreadsheetApp.getActive();
var names = ss.getSheetByName("sheet name");
var namesValues = names.getRange(2,14,names.getLastRow()-1).getValues();
var innerHTML = [];
for (var i=0;i<namesValues.length;i++){
if(namesValues[i][0]) {
innerHTML.push({value:''+ namesValues[i][0], text:namesValues[i][0]});
}
};
return innerHTML;
}
function createInnerHTML2() {
var ss = SpreadsheetApp.getActive();
var names = ss.getSheetByName("sheet name");
var namesValues = names.getRange(2,11,names.getLastRow()-1).getValues();
var innerHTML = [];
for (var i=0;i<namesValues.length;i++){
if(namesValues[i][0]) {
innerHTML.push({value:''+ namesValues[i][0], text:namesValues[i][0]});
}
};
return innerHTML;
}
And so on you can repeat the same function in the .gs file with many inputs in the .html file. Thanks again Cooper

Related

How can i dynamically add an Input select element on click of a button in ember

Am creating an ember application where am in need of dynamicaly adding a select element which will have options fetched from a server. so the select elements look like this. And instead of having all dropdown boxes predefined i need to add them dynamicaly like on a click of a button like( + add more). like
and each of those drop down boxes should contain the datas that is fetched from the server. plus i need a way to get the datas from those dynamically created select fields.
my .hbs for the current drop down page is..
map.hbs
<center><h4>Map</h4></center>
<container class = "cond">
{{#each this.model.sf as |row|}}
<select class = "sel">
{{#each this.model.sf as |sf|}}
<option value = {{sf.attrname}}>{{sf.attrname}}</option>
{{/each}}
</select><br>
{{/each}}
I tried ember-dynamic-fields but its depracted and I couldnt able to use it.. and all other solutions on web or for ember way older versions.. nothing works on ember 4.6 so could anyone helpout?
Using The Platform's native FormData functionality, demo'd here.
I think we can generate any number of inputs based on input data in the following way:
Store the form's state in some variable
conditionally show further select / inputs based on the properties in that form state.
Code-wise, that'd look like this:
{{#if (dataHasValueFor "fieldName")}}
Show previously hidden field
{{/if}}
And of course the devil is in the implementation details, so, a full working example (with sample data I made up -- we can iterate on this if you want for your specific data set, just leave a comment on this post/answer).
import Component from '#glimmer/component';
import { tracked } from '#glimmer/tracking';
import { on } from '#ember/modifier';
import { get } from '#ember/helper';
// This could be your model data from your route
const DATA = {
fruits: [
'apple', 'banana', 'orange', 'mango',
'watermellon', 'avacado', 'tomato?'
],
veggies: ['cocumber', 'tomato?', 'green bean', 'kale', 'spinach'],
peppers: ['carolina reaper', 'habanero', 'jalapeƱo']
}
export default class Demo extends Component {
#tracked formData;
get categories() {
return Object.keys(DATA);
}
handleInput = (event) => {
let formData = new FormData(event.currentTarget);
let data = Object.fromEntries(formData.entries());
this.formData = data;
}
handleSubmit = (event) => {
event.preventDefault();
handleInput(event);
}
isSelected = (name, value) => this.formData?.[name] === value;
<template>
<form
{{on 'input' this.handleInput}}
{{on 'submit' this.handleSubmit}}
>
<label>
Food Category<br>
<select name="category" placeholder="Select...">
<option selected disabled>Select a food group</option>
{{#each this.categories as |name|}}
<option
value={{name}}
selected={{this.isSelected "category" name}}
>
{{name}}
</option>
{{/each}}
</select>
</label>
<hr>
{{#let (get this.formData "category") as |selectedCategory|}}
{{#if selectedCategory}}
<label>
{{selectedCategory}}<br>
<select name={{selectedCategory}}>
<option selected disabled>
Select {{selectedCategory}}
</option>
{{#each (get DATA selectedCategory) as |food|}}
<option
value={{food}}
selected={{this.isSelected selectedCategory food}}
>
{{food}}
</option>
{{/each}}
</select>
</label>
{{/if}}
{{/let}}
</form>
<hr>
FormData:
<pre>{{toJson this.formData}}</pre>
</template>
}
const toJson = (input) => JSON.stringify(input, null, 4);
This demo is interactive here, on limber.glimdown.com
Note that the syntax used here is what will be default in the upcoming Polaris Edition of Ember, and is available via ember-template-imports
Update (after comments)
Demo here
I took some liberties with the how the fields are dynamic, because I think this more easily shows the concept asked about in the question: dynamically showing fields in a form.
import Component from '#glimmer/component';
import { tracked } from '#glimmer/tracking';
import { on } from '#ember/modifier';
import { get } from '#ember/helper';
export default class Demo extends Component {
#tracked formData;
handleInput = (event) => {
let formData = new FormData(event.currentTarget);
let data = Object.fromEntries(formData.entries());
this.formData = data;
}
handleSubmit = (event) => {
event.preventDefault();
handleInput(event);
}
<template>
<form
{{on 'input' this.handleInput}}
{{on 'submit' this.handleSubmit}}
>
<div class="grid">
<label>
Name <input type="checkbox" name='hasName'>
</label>
<label>
Email <input type="checkbox" name='hasEmail'>
</label>
<label>
Alias <input type="checkbox" name='hasAlias'>
</label>
<hr>
{{#if (get this.formData 'hasName')}}
<label>
Name
<input type="text" name="name" class="border" />
</label>
{{/if}}
{{#if (get this.formData 'hasEmail')}}
<label>
Email
<input type="email" name="email" class="border" />
</label>
{{/if}}
{{#if (get this.formData 'hasAlias')}}
<label>
Alias
<input type="text" name="alias" class="border" />
</label>
{{/if}}
</div>
</form>
<hr>
FormData:
<pre>{{toJson this.formData}}</pre>
</template>
}
const toJson = (input) => JSON.stringify(input, null, 4);
And... since it seems you have a lot of fields, you may want to go as dynamic as possible:
demo here
which is the following code:
<form
{{on 'input' this.handleInput}}
{{on 'submit' this.handleSubmit}}
>
<div class="grid">
{{#each FIELDS as |field|}}
<label>
{{field}} <input type="checkbox" name='has-{{field}}'>
</label>
{{/each}}
<hr>
{{#each FIELDS as |field|}}
{{#if (get this.formData (concat 'has-' field))}}
<label>
{{field}}
<input type="text" name={{field}} class="border" />
</label>
{{/if}}
{{/each}}
</div>
</form>
I guess Simple js code did the magic of adding and retriving data.. pity of me after finding out.. And for some dynamic ember formdata the previous answer from nullvox helped out.. so here is the code
.hbs
<table class="table">
<th>
<td>Sf</td>
</th>
<th>
<td>Db</td>
</th>
<tbody id = "map">
</tbody>
</table>
<button class = "btn btn-sm btn-primary" type="button" {{action "submit"}}>Submit</button>
<button class = "btn btn-success btn-sm" onclick = {{action "get"}} type="button">Add another</button>
controller code for creating element
#action
get() {
let div = document.getElementById('map');
let tr = document.createElement('tr');
let td = document.createElement('td');
let td2 = document.createElement('td');
var select = document.createElement('select');
select.setAttribute('class', 'sfselect');
div.appendChild(tr);
tr.appendChild(td);
td.appendChild(select);
for (var i = 0; i < sf.length; i++) {
var option = document.createElement('option');
option.value = sf[i];
option.text = sf[i];
select.appendChild(option);
}
var select2 = document.createElement('select');
select2.setAttribute('class', 'dbselect');
tr.appendChild(td2);
td2.appendChild(select2);
for (var i = 0; i < db.length; i++) {
var option = document.createElement('option');
option.value = db[i];
option.text = db[i];
select2.appendChild(option);
}
}
controller code for getting data
#action submit() {
var sfattr = document.querySelectorAll('.sfselect');
var dbattr = document.querySelectorAll('.dbselect');
var sf = [];
var db = [];
console.log(sfattr.length);
let datas;
for (var i = 0; i < sfattr.length; i++) {
sf[i] = sfattr[i].value;
db[i] = dbattr[i].value;
}
let m1 = sf.toString();
let m2 = db.toString();
$.ajax({
url: 'http://localhost:8080/lorduoauth/Map',
method: 'POST',
contentType: 'application/x-www-form-urlencoded',
data: {
m1: m1,
m2: m2,
},
success: function (response) {
console.log(datas);
alert(response);
},
error: function (xhr, status, error) {
var errorMessage = xhr.status + ': ' + xhr.statusText;
alert('error' + errorMessage);
},
});
}
thus the output looks like this

webapp form value to spreadsheet

I have a webapp form and I'm looking for a way to push the value of the form into google spreadsheet.
My current attempt is to assign a name to each form input (a1,a2,a3...) then attempt to iterate the form values into an array like this:
Code.gs
function doGet(e) {
return HtmlService
.createTemplateFromFile('Index')
.evaluate()
.setSandboxMode(HtmlService.SandboxMode.NATIVE)
}
function writeForm(form) {
var ss =
SpreadsheetApp.openById('1bKrGjBV*****');
var sheet = ss.getSheets()[0];
var data = ss.getDataRange().getValues();
var input = [''];
var ndata = form
for(var j=0;j<data.length;j++){
var value = form.a+j
input.push(value)
}
for(var k=0;k<data.length;k++){
sheet.getRange(k+1,4).setValue(ndata[k]);
}
var range = sheet.getRange(1, 5);
}
function getData(){
return SpreadsheetApp
.openById('1bKrGjBV*****')
.getSheets()[0]
.getDataRange()
.getValues();
}
Index.html
<body>
<center><h1>Produce Inventory Form </h1></center>
<style>
table,th,td{border:1px solid black;}
</style>
<? var data = getData(); ?>
<form id="invform">
<input type = "submit" value="Submit" onclick
="google.script.run.writeForm(this.parentNode)">
<table align="center">
<tr><th>Code</th><th>Name</th><th>ChName</th><th>On Hand</th></tr>
<? for(var i=0;i<data.length;i++){ ?>
<tr>
<th><?= data[i][0] ?></th>
<th><?= data[i][1] ?></th>
<th><?= data[i][2] ?></th>
<th><input type = "text" style="width:40px" min="0" maxlength="3" name=a<?
=i ?>>
</tr>
<? } ?>
</table>
</body>
With this method, the problem I'm getting into is
var value = form.a+j
Doesn't do what I was hoping for, which is to assign a variable to form.a1, form.a2, form.a3, ... then push it into an array.
I'm pretty sure there's a better way but I have yet to find a solution. Apologize for the messy code, but I was focused on getting the result.
How about a following modification?
Modification points :
For Index.html, </form> is missing.
About form.a+j, you can retrieve the values using form["a" + j].
ndata is JSON like {a1: "value", a2: "value"}. So when ndata is imported to cells, it becomes undefined.
When several values are imported to cells, the importing efficiency becomes higher by using setValues().
When these are reflected to your script, the modified script is as follows. The values inputted to forms are imported to "D1:D" of spreadsheet.
Modified script :
Code.gs
function doGet(e) {
return HtmlService
.createTemplateFromFile('Index')
.evaluate()
.setSandboxMode(HtmlService.SandboxMode.NATIVE)
}
function writeForm(form) {
var ss = SpreadsheetApp.openById('1bKrGjBV*****');
var sheet = ss.getSheets()[0];
var data = ss.getDataRange().getValues();
var input = []; // Modified
// var ndata = form
for(var j=0;j<data.length;j++){
var value = form["a" + j]; // Modified
input.push([value]) // Modified
}
sheet.getRange(1, 4, input.length, input[0].length).setValues(input); // Added
// for(var k=0;k<data.length;k++) {
// sheet.getRange(k+1,4).setValue(ndata[k]);
// }
// var range = sheet.getRange(1, 5);
}
function getData(){
return SpreadsheetApp
.openById('1bKrGjBV*****')
.getSheets()[0]
.getDataRange()
.getValues();
}
Index.html
<body>
<center><h1>Produce Inventory Form </h1></center>
<style>
table,th,td{border:1px solid black;}
</style>
<? var data = getData(); ?>
<form id="invform">
<input type = "submit" value="Submit" onclick="google.script.run.writeForm(this.parentNode)">
<table align="center">
<tr><th>Code</th><th>Name</th><th>ChName</th><th>On Hand</th></tr>
<? for(var i=0;i<data.length;i++){ ?>
<tr>
<th><?= data[i][0] ?></th>
<th><?= data[i][1] ?></th>
<th><?= data[i][2] ?></th>
<th><input type = "text" style="width:40px" min="0" maxlength="3" name=a<?= i ?>>
</tr>
<? } ?>
</table>
</form> <!-- Added -->
</body>
If I misunderstand your question, I'm sorry.

In meteor js ,In edit form i'm unable to display the dropdown box values which i stored during adding a form

I have a form that uses drop-down boxes to save information in mongo
Db. That works fine, but the problem comes when I am trying to edit
the information in the database.I used the same form (add form) to
edit the information. it pulls the values from the database and
displays the fields in the fields accordingly. However, I am having a
hard time figuring out how to populate the drop-down boxes with the
value from the database. Basically, I want the "option selected" tag
to be the database and be able to still have the rest of the options
to select from.in text box I am getting the text values from database
but in drop down I wont be able to get the value.
addmenu.html
<template name="addMenu">
<form class="addingMenus">
<p><input type="text" name="menuName" id="menuName" placeholder="Choose Label" value = {{menuName}}></p>
<p><input type="text" name="associatedPages" id="associatedPages" placeholder="Enter Associated Pages" value= {{associatedPages}}></p>
<p><input type="text" name="menuUrl" id="menuUrl" placeholder="Enter Page URl" value={{menuUrl}}></p>
<p>
<select id="level" >
<option name="parent" value="0" selected = {{rejected}}>parent level</option>
<option name="child" value="1" selected = {{accepted}}>child level</option>
</select>
<select id="childLevel" style="visibility:hidden">
{{#each parent}}
<option value = "{{this._id}}" selected = {{subMenu}} >{{this.menuName}}</option>
{{/each}}
</select>
</p>
<p>
<select id="publishStatus">
<option name="publish" value="true" selected="{{published}}">publish</option>
<option name="unpublish" value="false" selected="{{unpublished}}">unpublish</option>
</select>
</p>
<p><button type="button" class="save-button" id="{{task}}-save-button">SAVE</button></p>
</form>
</template>
addmenu.js:
Template.addMenu.events({
'click #add-menu-save-button': function (event,template) {
//event.preventDefault();
console.log(event);
var levelId = document.getElementById('level').value;
if (levelId == 1) {
parentId = document.getElementById('childLevel').value;
} else {
parentId = "null";
}
var publishStatus = document.getElementById('publishStatus').value;
//console.log(publishStatus);
let menuInsert = {
menuName: document.getElementById('menuName').value,
associatedPages: document.getElementById('associatedPages').value,
menuUrl: document.getElementById('menuUrl').value,
level: document.getElementById('level').value,
createdAt: new Date(),
publishStatus: publishStatus,
parentId: parentId
};
Meteor.call("addMenu", menuInsert, function (error, result) {
if(error) {
console.log("error in adding a menu");
} else {
alert("successfully entered in database");
Router.go('/administrator/admin');
}
});
},
'click #level': function (event, template) {
event.preventDefault();
console.log(document.getElementById('level').value);
if(document.getElementById('level').value == '1') {
document.getElementById("childLevel").style.visibility = "visible";
console.log("iam in session in level");
} else {
document.getElementById("childLevel").style.visibility = "hidden";
}
}
});
Template.addMenu.helpers({
parent: function () {
return menuDetails.find({level: "0"});
},
accepted: function (event) {
console.log(this.level);
if(this.level == "1") {
Session.set('submenu',this.parentId);
console.log(Session.get('submenu'));
return "selected";
}
},
rejected: function (event) {
if(this.level == "0") {
return "selected";
}
},
subMenu: function (event) {
var id = Session.get('submenu');
console.log(this._id);
if(id == this._id) {
return "selected";
}
},
published: function (event) {
if(this.publishStatus == true)
return "selected";
},
unpublished: function (event) {
if(this.publishStatus == false)
return "selected";
}
});
you need to modify your template like this.
<select id="childLevel" style="visibility:hidden">
{{#each parent}}
<option {{isSelected this.menuName}} value = "{{this._id}}">{{this.menuName}}</option>
{{/each}}
</select>
then in the helper you need to write this custom helper.
Template.addMenu.helpers({
isSelected: function(menuName){
return (menuName == 'your conditional value here') ? 'selected': '';
}
});

CodeIgniter: Multi-select input isn't able to select multiple values

Ironically, form_multiselect() I created didn't work for me. Actually it was created but I couldn't select multiple options. I followed the instructions on the user guide but still not functioning like a multi-select although it looks like one. Any silly mistakes I've made?
This is what the code looks like in web browser's inspect element feature:
<select name="meal_type[]" id="meal_type_id" onfocus="calculateTotal();" onblur="calculateTotal();" onchange="calculateTotal();" multiple="multiple">
<option value="Breakfast_1000">Breakfast</option>
<option value="Dinner_2500">Dinner</option>
<option value="Lunch_2000">Lunch</option>
</select>
This is what I coded in View:
<div class="control-group">
<label for="meal_type" class="control-label">
<i class="icon-glass"></i> Meal Type:
</label>
<div class="controls">
<?php
$js = 'id="meal_type_id" onFocus="calculateTotal();" onBlur="calculateTotal();" onChange="calculateTotal();"';
echo form_multiselect('meal_type[]', $mt_name, set_value('meal_type'), $js);
?>
<?php echo form_error('meal_type'); ?>
</div>
JAVASCRIPT
function calculateTotal() {
var room_type_id = document.getElementById('room_type_id').value;
var room_type_cost = room_type_id.split("_");
var meal_type_id = document.getElementById('meal_type_id').value;
var meal_type_cost = meal_type_id.split("_");
var ext_beds_id = document.getElementById('ext_beds_id').value;
var ext_beds_cost = ext_beds_id.split("_");
var reservation_duration = document.getElementById('reservation_duration').value;
var total_payable = ( parseInt(room_type_cost[1]) + parseInt(meal_type_cost[1]) + parseInt(ext_beds_cost[1]) ) * parseInt(reservation_duration);
document.getElementById('total_amount').value = total_payable;
}

Auto Refresh Div Content Using jQuery and AJAX passing variables

I am trying to setup a page where the users can select 1 criteria from a select menu and then select the second from another.
I would then like these variables to pass through my auto updating div using ajax so that they are used in the .php that is refreshed.
The select menu is working fine but how would I pass the values through ajax and then make sure it remembered them for the refresh.
FORM
<select id="employee_user">
<option value="">--</option>
<option value="333">Test User</option>
<option value="111">Testing Testing</option>
</select>
<select id="they" onchange="showUser(this.value, employee_user.value)">
<option value="">--</option>
<option value="20120801" class="333" title="Test User">20120801</option>
<option value="20110801" class="333" title="Test User">20110801</option>
<option value="20100801" class="333" title="Test User">20100801</option>
<option value="20120801" class="111" title="Testing Testing">20120801</option>
<option value="20110801" class="111" title="Testing Testing">20110801</option>
</select>
</form>
AUTO REFRESHING DIV
<script>
(function($)
{
$(document).ready(function()
{
$.ajaxSetup(
{
cache: false,
beforeSend: function() {
$('#updatingdiv').hide();
$('#loading').show();
},
complete: function() {
$('#loading').hide();
$('#updatingdiv').show();
},
success: function() {
$('#loading').hide();
$('#updatingdiv').show();
}
});
var $container = $("#updatingdiv");
$container.load("getholidaylog.php");
var refreshId = setInterval(function()
{
$container.load('getholidaylog.php');
}, 9000);
});
})(jQuery);
</script>
<div id="updatingdiv"></div>
<img src="loading.gif" id="loading" alt="loading" style="display:none;" />
and then getholidaylog.php would:
$year = $_GET["year"];
$username = $_GET["username"];
and use for the database query.
EDIT
$j(document).ready(function() {
$j("#year_select").change(function (){
$.ajaxSetup(
{
cache: false,
beforeSend: function() {
$('#updatingdiv').hide();
$('#loading').show();
},
complete: function() {
$('#loading').hide();
$('#updatingdiv').show();
},
success: function() {
$('#loading').hide();
$('#updatingdiv').show();
}
});
var $container = $("#updatingdiv");
var user_select= $j('#user_select').val();
var year_select= $j('#year_select').val();
$container.load('getholidaylog.php',{username:user_select,year:year_select});
var refreshId = setInterval(function()
{
$container.load('getholidaylog.php');
}, 9000);
});
})(jQuery);
**
Following code passing the values to php page successfully
<script type="text/javascript">
$(document).ready(function(){
$("#they").change(function () {
var firstVal = $("#employee_user").val();
var secVal = $("#they").val();
$.ajax({
type: "POST",
data: "year="+ firstVal +"&username="+ secVal,
url: "getholidaylog.php",
success: function(msg){
$("#updatingdiv").html(msg);
}
});
});
});
</script>
but instead of loading the getholidaylog.php into div load the content of respective page into the div
DO Something like this..
Add two hidden fields in your html like this:
-------
<input type="hidden" id="userselect" />
<input type="hidden" id="yearselect" />
</form>
Now Change your jQuery code like this..
Modify your onchange function of year_select like this and put it separately . Dont include ajax setup in this.
$j("#year_select").change(function (){
$('#userselect').val($('#employee_user').val());
$('#yearselect').val($('#they').val());
});
Now take the value from hidden field.change these lines.
var user_select= $j('#userselect').val();
var year_select= $j('#yearselect').val();
So your Final hmtl markup would look like this:
<select id="employee_user">
<option value="">--</option>
<option value="333">Test User</option>
<option value="111">Testing Testing</option>
</select>
<select id="they" onchange="showUser(this.value, employee_user.value)">
<option value="">--</option>
<option value="20120801" class="333" title="Test User">20120801</option>
<option value="20110801" class="333" title="Test User">20110801</option>
<option value="20100801" class="333" title="Test User">20100801</option>
<option value="20120801" class="111" title="Testing Testing">20120801</option>
<option value="20110801" class="111" title="Testing Testing">20110801</option>
</select>
<select id="employee_user">
<option value="">--</option>
<option value="333">Test User</option>
<option value="111">Testing Testing</option>
</select>
<select id="they" onchange="showUser(this.value, employee_user.value)">
<option value="">--</option>
<option value="20120801" class="333" title="Test User">20120801</option>
<option value="20110801" class="333" title="Test User">20110801</option>
<option value="20100801" class="333" title="Test User">20100801</option>
<option value="20120801" class="111" title="Testing Testing">20120801</option>
<option value="20110801" class="111" title="Testing Testing">20110801</option>
</select>
<input type="hidden" id="userselect" />
<input type="hidden" id="yearselect" />
</form>
and your code will look like this:
$(function(){
$("#year_select").change(function (){
$('#userselect').val($('#employee_user').val());
$('#yearselect').val($('#they').val());
});
$.ajaxSetup(
{
cache: false,
beforeSend: function() {
$('#updatingdiv').hide();
$('#loading').show();
var user_select= $j('#userselect').val();
var year_select= $j('#yearselect').val();
},
complete: function() {
$('#loading').hide();
$('#updatingdiv').show();
},
success: function() {
$('#loading').hide();
$('#updatingdiv').show();
}
});
$container.load('getholidaylog.php',{username:user_select,year:year_select});
var refreshId = setInterval(function()
{
$container.load('getholidaylog.php');
}, 9000);
})
The low level $.ajax() method contains a variable called data through which you can pass data to the server. So if you want the send data in this case, you can do something like:
$.ajax({
data: {year:1999,username:'Codded'}
});
Same goes for load, the second parameter there is for passing data, so you can do
$("#divId").load('foo.php',{username:'Codded',year:1999});
u can use the data attribute of the ajax function to pass the selected value like this example :
$.ajax({
data: {'name': 'Dan'} // name is the name of the variable and Dan is the value in your case if the selected value
});
Check out your id of select is same as given below because it does not matches with the select box you have coded
var user_select= $j('#user_select').val();
var year_select= $j('#year_select').val();