日期:2014-05-16  浏览次数:20674 次

ajax prototype 修改 textbox 的值
<p><span class="left" style="width: 100px;">经销商区域:</span><input type="text" class="tb" id="chldealerarea"  name="chldealerarea" value="${clubHotLeads.chldealerarea }" readonly="readonly"/>(只读)</p>
<p><span class="left" style="width: 100px;">经销商小区:</span><input type="text" class="tb" id="chlzonename" name="chlzonename" value="${clubHotLeads.chlzonename }" readonly="readonly"/>(只读)</p>

即使textbox只读,也能通过js来修改value?

?

function checkDealCode() {
  	var chldealercode = $('chldealercode').value;
  	var ajax = new Ajax.Request('checkDealCode.action', {
        	method: 'post',
	        parameters: {
	        	'chldealercode': chldealercode
	        },
	        onSuccess: function(transport){
	            var json = transport.responseText.evalJSON() || false;
	            if (json) {
	                if (json.msg) {
	                    alert(json.msg);
	                } else {
	                	$('chlzonename').setValue(json.chlzonename);
	                	$('chldealerarea').setValue(json.chldealerarea);
	                }
	            } else {
	                alert('数据获取失败。');
	            }
	        },
	        onFailure: function(){
	            alert('服务器连接失败。');
	        }
	    });
  }

?

后端JAVA:

//小区名
	private String chlzonename;
	//大区名
	private String chldealerarea;

两个属性的 get() set()

@Action(value = "checkDealCode",
			results={@Result(type = "json", name = SUCCESS)}
	)
	public String checkDealCode(){
		log.info("method begin:checkDealCode()");
		try{
			if (!StrUtils.checkEmpty(chldealercode)) {
				log.info("method end:checkDealCode()");
				return SUCCESS;
			}
			ClubDealer clubDealer = clubDealerMng.getClubDealerBySalecode(chldealercode);
			if (clubDealer == null) {
				msg = "此经销商CODE不存在。";
			} else {
				chlzonename = clubDealer.getClubDealerSmallArea().getDlzonename();
				chldealerarea = clubDealer.getDlaname();
			}
		} catch (DataAccessException ex) {
			log.error("", ex);
			msg = ex.getMessage();
		} catch (BusinessAccessException ex) {
			log.error("", ex);
			msg = ex.getMessage();
		} catch (Exception ex) {
			log.error("", ex);
			msg = ex.getMessage();
		} catch (Throwable ex) {
			log.error("", ex);
			msg = ex.getMessage();
		}
		log.info("method end:checkDealCode()");
		return Constants.SUCCESS;
	}
?

?

?