JavaScript - Postback And Clientclick
Hej all,
I have this issue. Code: <asp:Button PostBackUrl="www.google.com" runat="server" OnClientClick="Validate();" /> Problem is that i get to the postback page before the validation is finished. In fact my validation is saving something in the database and there is my problem. Anyone has any suggestions? Similar Tutorialshi all, I have a very serious problem with the coda-slider (I guess you know the coda-slider). I have 5 panels with lots of content, I have a panel buttons and DropDownLists. When I click one of this buttons or dropdownlist, the javascript function that calls the coda-slider is lost and does not work. Any ideas? thanks... hello Friends In my jsp project i am using the calendar control which selects the Birth Date of the client and on that basis it calculates the age after completion of all the fields user get registered successfully.but when registered user trying to update his date of birth his age field is blank please tell me why this happening Also please tell me the javascript function My jsp code is: Code: <%@page import="java.lang.reflect.Array"%> <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %> <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %> <%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %> <%@page import="java.util.ArrayList"%> <%@page import="com.udhc.model.City"%> <%@page import="com.udhc.model.User" %> <%@page import="com.udhc.model.Country"%> <%@page import="com.udhc.model.State"%> <%@page import="com.udhc.config.ApplicationConstant"%> <%@page import="org.apache.struts.Globals" %> <%@page import="com.udhc.utility.CommanUtility"%> <%@page import="java.util.HashMap"%> <%@page import="com.udhc.form.UserForm"%> <%@page import="com.udhc.utility.DateUtlity"%> <%@page import="java.util.Calendar"%> <jsp:include page="Header.jsp"></jsp:include> <link type="text/css" href="css/jquery.ui.core.css" rel="stylesheet" /> <link type="text/css" href="css/jquery.ui.datepicker.css" rel="stylesheet" /> <link type="text/css" href="css/jquery.ui.theme.css" rel="stylesheet" /> <link type="text/css" href="css/calendar.css" rel="stylesheet"></link> <script type="text/javascript" language="javascript" src="js/jquery.js"></script> <script type="text/javascript" language="javascript" src="js/jquery.ui.core.js"></script> <script type="text/javascript" language="javascript" src="js/jquery.ui.widget.js"></script> <script type="text/javascript" language="javascript" src="js/jquery.datepicker.js"></script> <script type="text/javascript" language="javascript" src="js/calendar.js"></script> <script type="text/javascript"> <% User user= (User)session.getAttribute(ApplicationConstant.UDHC_USER_MODEL); %> // Array of max days in month in a year and in a leap year function addUser() { if(validate()) { document.forms[0].method = "POST"; document.forms[0].nextStep.value = "addUser"; document.forms[0].action = "User.do"; document.forms[0].submit(); } } function updateUser() { if(validate()) { document.forms[0].method = "POST"; document.forms[0].nextStep.value = "updateUser"; document.forms[0].action = "User.do"; document.forms[0].submit(); } } function ClearOptions(OptionList) { for (x = OptionList.length; x >= 0; x = x - 1) { OptionList[x] = null; } } function AddToOptionList(OptionList, OptionValue, OptionText) { OptionList[OptionList.length] = new Option(OptionText, OptionValue); } } function getSecretQuestion() { var questionId=document.forms[0].secretQuestion.value; if(questionId== "") { alert("Select Secret question"); } else { $ajax({ type: "get", url: "Register.do", error: function(data){alert("Error");} }); } } function finish() { var countryId = document.forms[0].country.value; if(countryId == "") { alert("Please select country."); } else { $.ajax({ type: "get", url: "Register.do", data: "nextStep=getStateListByCountry&country="+countryId, error: function(data) {alert("Error");}, success: function(response) { var stateList = document.forms[0].state; ClearOptions(stateList); AddToOptionList(stateList,"","Select State"); $.each($(response).find("state"), function(i, state) { var stateId = $(state).children("stateId").text(); var stateName = $(state).children("stateName").text(); AddToOptionList(stateList,stateId,stateName); }); } }); } } </script> <% ArrayList<City> cityList =(ArrayList<City>)request.getAttribute("CITY_LIST"); ArrayList<Country> countryList =(ArrayList<Country>)request.getAttribute("COUNTRY_LIST"); ArrayList<State> stateList =(ArrayList<State>)request.getAttribute("STATE_LIST"); %> <div> </div> <input type="hidden" name="<%=org.apache.struts.taglib.html.Constants.TOKEN_KEY %>" value="<bean:write name="<%=Globals.TRANSACTION_TOKEN_KEY%>"/>" /> <div style="float: left;"> <logic:notEmpty name="UPDATE_USER"> <a href="User.do?nextStep=userHome">Back</a> </logic:notEmpty> </div> <div style="width: 700px; margin-left: 100px;" class="border"> <table class="back_img" cellspacing="5" width="100%" height="600"> <tr valign="top"> <td height="10"><h3><u>User Registration</u></h3></td> </tr> <tr valign="top"> <td> <table> <tr> <td> </td> </tr> <!--<tr> <td><b>Name:</b> </td> <td><input type="text" name="firstName" class="textfield"/> <input type="text" name="middleName" class="textfield"/> <input type="text" name="lastName" class="textfield"/></td> </tr> <tr> <td width="200"> </td> <td> First Name Middle Name Last Name</td> </tr>--> <tr> <td><span style="color:red;font-size:small;visibility: true">*</span><b>Gender:</b></td> <td><html:radio property="gender" name="UserForm" value="<%=ApplicationConstant.GENDER_MALE %>" tabindex="1"/>Male <html:radio property="gender" name="UserForm" value="<%=ApplicationConstant.GENDER_FEMALE %>" tabindex="2"/>Female <span style="color:red;font-size:small;visibility: true">*</span> <b>Birth Date: </b> <input type="text" name="dateOfBirth" readonly="readonly" value="<bean:write property="dateOfBirth" name="UserForm"/>" ><a href="#" onClick="setYears(1900, 2013); showCalender(this, 'dateOfBirth');" > <img src="images/calendar.gif"></a> <span style="color:red;font-size:small;visibility: true">*</span><b>Age: </b> <!-- <input type="text" id='idAge' name="age" class="textfield4" ondblclick="closeCalender();calcAge();" tabindex="4" maxlength="3"></input>--> <input type="text" id='idAge' name="age" class="textfield4" onclick="pickDate(month,day,year);" tabindex="4" maxlength="3"></input> </td> </tr> <tr> <td><span style="color:red;font-size:small;visibility: true">*</span><b>Password:</b></td> <td><html:password name="UserForm" property="userPassword" styleClass="textfield"/></td> </tr> <tr> <td><span style="color:red;font-size:small;visibility: true">*</span><b>Confirm Password:</b> </td> <td><input type="password" name="confirmPassword" class="textfield" value="<bean:write name="UserForm" property="userPassword"/>"/></td> </tr> <tr> <td><span style="color:red;font-size:small;visibility: true">*</span><b>Secret Question:</b> </td> <td><select name="secretQuestion" class="selectfield" style="width:220px;"> <option value="">Select secret Question?</option> <% HashMap<String, String> qHash = CommanUtility.getQuestion(); if(session.getAttribute(ApplicationConstant.UDHC_USER_MODEL) != null) { //User user = (User)session.getAttribute(ApplicationConstant.UDHC_USER_MODEL); if(user != null) { for(int i = 1; i <= qHash.size(); i++) { if((i+"").equals(user.getSecretQuestion())) { %> <option value="<%=i %>" selected="selected"><%=qHash.get(i+"") %></option> <% } else { if(qHash.get(i+"") != null) { %> <option value="<%=i %>"><%=qHash.get(i+"") %></option> <% } } } } } else { for(int i = 1; i <= qHash.size(); i++) { if(qHash.get(i+"") != null) { %> <option value="<%=i %>"><%=qHash.get(i+"") %></option> <% } } } %> </select> </td> </tr> <tr> <td><span style="color:red;font-size:small;visibility: true">*</span><b>Secret Answer:</b> </td> <td><html:text property="secretAnswer" name="UserForm" styleClass="textfield"/></td> </tr> <tr> <td><b>Contact details:</b> </td> <td> </td> </tr> <tr> <td> </td> <td> <table> <tr> <td><span style="color:red;font-size:small;visibility: true">*</span>Address 1:</td> <td><html:text property="address1" name="UserForm" styleClass="textfield1"/></td> </tr> <tr> <td>Address 2:</td> <td><html:text property="address2" name="UserForm" styleClass="textfield1"/></td> </tr> </table> <table> <tr> <td><span style="color:red;font-size:small;visibility: true">*</span>Country: </td> <td> <html:select property="country" name="UserForm" styleClass="selectfield" onchange="javascript:getStateList();"> <html:option value="">Select Country</html:option> <html:optionsCollection name="COUNTRY_LIST" value="countryId" label="name" /> </html:select> </td> </tr> <tr> <td><span style="color:red;font-size:small;visibility: true">*</span>State:</td> <td> <html:select property="state" name="UserForm" styleClass="selectfield" onchange="javascript:getCityList();"> <html:option value="">Select State</html:option> <html:optionsCollection name="STATE_LIST" value="stateId" label="name" /> </html:select> </td> <td><span style="color:red;font-size:small;visibility: true">*</span>City: </td> <td> <html:select property="cityId" name="UserForm" styleClass="selectfield"> <html:option value="">Select City</html:option> <html:optionsCollection name="CITY_LIST" value="cityId" label="name" /> </html:select> </td> <td>PIN:</td> <td><html:text property="pinCode" name="UserForm" styleClass="textfield"/></td> </tr> <tr> <td>Phone: </td> <td><html:text property="phone" name="UserForm" styleClass="textfield"/></td><td><span style="color:red;font-size:small;visibility: true">*</span>Cell:</td><td><html:text property="cellNo" name="UserForm" styleClass="textfield"/></td> </tr> <tr> <td><span style="color:red;font-size:small;visibility: true">*</span>Email: </td> <td colspan="4"><html:text property="email" name="UserForm" styleClass="textfield1"/></td> </tr> </table> </td> </tr> <tr> <td valign="top"><b>Other Relevant Information:</b></td> <td> <table> <tr> <td>Height:</td> <td><html:text property="height" name="UserForm" styleClass="textfield3"/><b>Cm.</b></td> <td>Weight:</td> <td><html:text property="weight" name="UserForm" styleClass="textfield3"/><b>Kg</b></td> </tr> <tr> <td>Blood Pressu </td> <td><html:text property="bPSystolic" name="UserForm" styleClass="textfield4"/> <html:text property="bPDiastolic" name="UserForm" styleClass="textfield4"/><b>mmHg</b></td> <td>Pulse rate:</td> <td><html:text property="pulseRate" name="UserForm" styleClass="textfield3"/></td> </tr> </table> </td> </tr> <logic:empty name="UPDATE_USER"> <tr> <td> </td> <td align="char" colspan="2" rowspan="2"><a href="javascript:addUser();"><img src="images/Register1.png" border="0"></img></a> <a href="index.jsp"><img src="images/Cancel1.png" border="0"></img></a></td> </tr> </logic:empty> <logic:notEmpty name="UPDATE_USER"> <tr> <td> </td> <td align="char"><a href="javascript:updateUser();"><img src="images/update.png" border="0"></img></a> <a href="User_Home.jsp"><img src="images/Cancel1.png" border="0"></img></a></td> </tr> </logic:notEmpty> </table> </td> </tr> <logic:messagesPresent message="true"> <tr> <td colspan="2" align="center"> <html:messages id="message" message="true"> <div class="error"> <bean:write name="message"/> </div> </html:messages> </td> </tr> </logic:messagesPresent> </div> </table> <table id="calenderTable"> <tbody id="calenderTableHead"> <tr> <td colspan="4" align="center"> <select onChange="showCalenderBody( createCalender(document.getElementById('selectYear').value, this.selectedIndex, false));" id="selectMonth"> <option value="0">Jan</option> <option value="1">Feb</option> <option value="2">Mar</option> <option value="3">Apr</option> <option value="4">May</option> <option value="5">Jun</option> <option value="6">Jul</option> <option value="7">Aug</option> <option value="8">Sep</option> <option value="9">Oct</option> <option value="10">Nov</option> <option value="11">Dec</option> </select> </td> <td colspan="2" align="center"> <select onChange="showCalenderBody(createCalender(this.value, document.getElementById('selectMonth').selectedIndex, false));" id="selectYear"> </select> </td> <td align="center"> <a href="#" onClick="closeCalender();calcAge();"> <font color="#003333" size="+1">X</font> </a> </td> </tr> </tbody> <tbody id="calenderTableDays"> <tr style=""> <td>Sun</td><td>Mon</td><td>Tue</td><td>Wed</td> <td>Thu</td><td>Fri</td><td>Sat</td> </tr> </tbody> <tbody id="calender"></tbody> </table> <jsp:include page="Footer.jsp"></jsp:include> Hi All, This is in ASP.Net Im creating a task loggin system and this allows the user to raise tasks and update them, im using javascript for validation and if the fields are empty it then changes the fields back ground to Red which is fine but then it goes on to update the data in SQL which i dont want, any suggestions or how i can achieve no post back is the result from the function is False (for fields in error) Html Code where im calling the function Code: <asp:button runat="server" id="btnChangeCommentsAuth" CSSclass="RaiseButton" OnClientClick="CommentsCheck('MainDisplayContentChange_txtAuthCommentsArea');" PostBackUrl="~/RaiseTaskChange.aspx" Text="Auth" /> Javascript function Code: function CommentsCheck(comments) { var com; var result = new boolean(); com = document.getElementById(comments); if (document.getElementById(comments).value == '') { com.style.backgroundColor = "#B20635"; result = 0; } else { result = 1 } } Thanks in Advance look forward to your reply. |